package com.aaa.sys.controller;


import com.aaa.vo.R;
import com.aaa.sys.service.LoginLogService;
import com.aaa.sys.vo.LoginLogResult;
import com.aaa.sys.vo.LoginLogVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 登录记录 前端控制器
 * </p>
 *
 * @author ykq
 * @since 2020-12-08
 */
@RestController
@RequestMapping("/system/loginLog")
public class LoginLogController {


    @Autowired
    private LoginLogService loginLogService;

    @PostMapping("findByCondition/{current}/{limit}")
    public R findByCondition(@PathVariable Integer current, @PathVariable Integer limit, @RequestBody LoginLogVo loginLogVo){
        IPage<LoginLogResult> page=this.loginLogService.findByCondition(current,limit,loginLogVo);
        return R.ok().data("records",page.getRecords()).data("total",page.getTotal());
    }

    @GetMapping("clearLoginLog")
    public R clearLoginLog(){
        try {
            this.loginLogService.clearLoginLog();
            return R.ok().message("清除登陆日志成功");
        }catch (Exception e){
            e.printStackTrace();
            return R.error().message("清除登陆日志失败");
        }
    }
}

